package com.xuecheng.checkcode.infrastructure.util;

import java.util.Random;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-09-07  18:33
 */
public class RandomUtil {

    private static final String STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    public static final Integer DEFAULT_LENGTH = 4;

    public static String getRandom(int length){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for(int i = 0;i < length; i++){
            int number = random.nextInt(36);
            sb.append(STR.charAt(number));
        }
        return sb.toString();
    }

    public static String getRandom(){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for(int i = 0;i < DEFAULT_LENGTH; i++){
            int number = random.nextInt(36);
            sb.append(STR.charAt(number));
        }
        return sb.toString();
    }
}
